package rsj.sql.org;

import com.rlyy.aibase.utils.base.MapNode;
import rsj.annotation.Param;
import rsj.annotation.Select;
import rsj.annotation.Update;
import rsj.api.account.entity.Organization;
import rsj.api.organization.entity.UpdateIp;

/**
 * 机构
 *
 * @author yuanqinglong
 * @since 2021/7/16 10:16
 */
public interface OrganizationDao {


    /**
     * 加入组织
     *
     * @param createOrganization 创建组织
     */
    @Update(value = "INSERT INTO sys.sys_org (org_id,org_cust_id,org_type,org_ip,org_user_name,org_utime) VALUES (#{orgId},#{custId},#{orgType},#{orgIp},#{orgUserName},#{orgUtime})")
    void addOrganization(Organization createOrganization);


    /**
     * 得到组织
     *
     * @param orgId org id
     * @return {@link MapNode}
     */
    @Select(value = "SELECT org_id,org_type,org_ip,concat('RSJ',lpad(org_cust_id::text,4,'0')) AS cust_show_id,cust_id,cust_sname FROM sys.sys_org LEFT JOIN sys.sys_cust ON cust_id = org_cust_id WHERE org_id = #{orgId}")
    MapNode getOrganization(@Param(value = "orgId") String orgId);


    /**
     * 更新的ip地址
     *
     * @param updateIp 更新的ip
     */
    @Update(value = "UPDATE sys.sys_org SET org_ip = #{orgIp} WHERE org_id = #{orgId}")
    void updateIpAddress(UpdateIp updateIp);
}
